package miniproj.services.util;

import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.util.Scanner;

/**
 * This static class provide common tools to the Simulators
 * 
 * @author William Tassoux
 * 
 */
public class SimulatorHelper {

	/**
	 * Gets the next int.
	 * 
	 * @param in
	 *            the scanner used to read the input
	 * @param start
	 *            the start range
	 * @param end
	 *            the end range
	 * @return the next int entered by the user, matching the range specified.
	 */
	public static int getNextInt(Scanner in, int start, int end) {
		boolean validInput = false;
		int result;

		result = start;
		do {
			try {
				result = in.nextInt();
				if (result >= start && result <= end) {
					validInput = true;
				} else
					System.out.println("Erreur: Mauvais choix selectionne");
			} catch (InputMismatchException e) {
				System.out.println("Erreur: Mauvais choix selectionne");
				in.next();
			} catch (NoSuchElementException e) {
			}
		} while (!validInput);
		return result;
	}
}
